package cn.maihe.elg.operation.centers.follow.channel;

import cn.maihe.elg.operation.centers.follow.channel.dto.FollowBaseRespDTO;
import cn.maihe.elg.operation.model.dto.BaseReq;
import cn.maihe.elg.operation.utils.IdGenerate;

import java.util.HashMap;
import java.util.Map;

/**
 * @Description
 * @Author WJH
 * @Date 2021/04/21
 */
public class FollowContext<REQ extends BaseReq, RESP extends FollowBaseRespDTO> {

    private final REQ req;
    private RESP resp;
    private final Map<String, Object> voMap = new HashMap<>();
    private final String traceId;

    public FollowContext(REQ req, Map<String, Object> attrMap) {
        this.req = req;
        this.traceId = IdGenerate.genTranceId();
        if(attrMap!=null){
            voMap.putAll(attrMap);
        }
    }

    public REQ getReq() {
        return req;
    }

    public RESP getResp() {
        return resp;
    }

    public void setResp(RESP resp) {
        this.resp = resp;
    }

    public void setAttr(String key, Object attrValue) {
        voMap.put(key, attrValue);
    }

    public <V> V getAttr(String key) {
        return (V) voMap.get(key);
    }

    public String getTraceId() {
        return traceId;
    }
}
